<template>
  <div class="avue-top">
    <div class="top-bar__left">
      <div class="avue-breadcrumb"
           :class="[{ 'avue-breadcrumb--active': isCollapse }]"
           v-if="showCollapse">
        <i class="icon-navicon"
           @click="setCollapse"></i>
      </div>
    </div>
    <div class="top-bar__title">
      <div class="top-bar__item top-bar__item--show"
           v-if="showMenu">
        <top-menu ref="topMenu"></top-menu>
      </div>
      <span class="top-bar__item"
            v-if="showSearch">
        <top-search></top-search>
      </span>
    </div>
    <div class="top-bar__right">
<!--      <el-tooltip v-if="showColor"-->
<!--                  effect="dark"-->
<!--                  :content="$t('navbar.color')"-->
<!--                  placement="bottom">-->
<!--        <div class="top-bar__item">-->
<!--          <top-color></top-color>-->
<!--        </div>-->
<!--      </el-tooltip>-->
        <el-tooltip v-if="showColor"
                    effect="dark"
                    content="机器人小助手"
                    placement="bottom">
          <div class="top-bar__item">
            <KwRobotTrain :hasTrainBtn="false" class="robot-train"/>
          </div>
        </el-tooltip>
      <!-- <el-tooltip v-if="showDebug"
                  effect="dark"
                  :content="logsFlag?$t('navbar.bug'):logsLen+$t('navbar.bugs')"
                  placement="bottom">
        <div class="top-bar__item">
          <top-logs></top-logs>
        </div>
      </el-tooltip> -->
      <el-tooltip v-if="showLock"
                  effect="dark"
                  :content="$t('navbar.lock')"
                  placement="bottom">
        <div class="top-bar__item">
          <top-lock></top-lock>
        </div>
      </el-tooltip>
      <el-tooltip v-if="showTheme"
                  effect="dark"
                  :content="$t('navbar.theme')"
                  placement="bottom">
        <div class="top-bar__item top-bar__item--show">
          <top-theme></top-theme>
        </div>
      </el-tooltip>
      <el-tooltip effect="dark"
                  :content="$t('navbar.notice')"
                  placement="bottom">
        <div class="top-bar__item top-bar__item--show">
          <top-notice></top-notice>
        </div>
      </el-tooltip>
      <el-tooltip effect="dark"

                  :content="$t('navbar.language')"
                  placement="bottom">
        <div class="top-bar__item top-bar__item--show">
          <top-lang></top-lang>
        </div>
      </el-tooltip>
      <el-tooltip v-if="showFullScren"
                  effect="dark"
                  :content="isFullScren?$t('navbar.screenfullF'):$t('navbar.screenfull')"
                  placement="bottom">
        <div class="top-bar__item">
          <i :class="isFullScren?'icon-tuichuquanping':'icon-quanping'"
             @click="handleScreen"></i>
        </div>
      </el-tooltip>
      <img class="top-bar__img"
           :src="userInfo.avatar">
      <el-dropdown>
        <span class="el-dropdown-link top-bar-userInfo">
          <span class="top-bar-userAccount">{{userInfo.account}}</span>
          <span class="top-bar-tenantName" :alt="currentTenantAll.tenantName" :title="currentTenantAll.tenantName">({{currentTenantAll.tenantName}})</span>
          <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <!-- <el-dropdown-item>
            <router-link to="/">{{$t('navbar.dashboard')}}</router-link>
          </el-dropdown-item> -->
          <el-dropdown-item>
            <router-link to="/info/index?tab=userinfo">{{$t('navbar.userinfo')}}</router-link>
          </el-dropdown-item>
          <el-dropdown-item v-if="userInfo.isAdmin === '1'" @click.native="switchTenant">
            {{$t('navbar.switchTenant')}}
          </el-dropdown-item>

          <el-dropdown-item style="display: none;"  @click.native="AiCOSLicense">
            系统授权
          </el-dropdown-item>
          <el-dropdown-item  @click.native="showUpdateLog">
            升级日志
          </el-dropdown-item>

          <el-dropdown-item @click.native="logout"
                            divided>{{$t('navbar.logOut')}}
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <LicenseModel
      :title="LicenseTitle"
      :isShow.sync="isShow"
      :paramData="lsData"
      @successFun="lsSuccessFun"
    ></LicenseModel>
    <topTenant ref="topTenant"/>

    <HuilanDialog title="升级日志"
      :fullscreen="false"
      width="660px"
      append-to-body
      :visible.sync="updateLogTag"
      >
      <UpdateLog :showLicense="false" style="height: 70vh" />
    </HuilanDialog>


  </div>
</template>
<script>
import {resetRouter} from '@/router/router'
import {mapGetters, mapState} from "vuex";
import {fullscreenToggel, listenfullscreen} from "@/util/util";
import topLock from "./top-lock";
import topMenu from "./top-menu";
import topSearch from "./top-search";
import topTheme from "./top-theme";
import topLogs from "./top-logs";
// import topColor from "./top-color";
import topNotice from './top-notice'
import topLang from "./top-lang";
import topTenant from './top-tenant';
//机器人训练Demo组件
import KwRobotTrain from "@/components/kwRobotTrain/index";

import LicenseModel from '@/views/license/index';
import UpdateLog from "@/views/updateLog";

export default {
  components: {
    topLock,
    topMenu,
    topSearch,
    topTheme,
    topLogs,
    // topColor,
    topNotice,
    topLang,
    topTenant,
    LicenseModel,
    UpdateLog,
    KwRobotTrain
  },
  name: "top",
  data() {
    return {
      isShow: false,
      lsData:{
        handleType: '',
        isApp: false,
        needLast: false,
        params:{},
      },

      LicenseTitle:'更新授权',
      updateLogTag: false,
    };
  },
  filters: {},
  created() {
  },
  mounted() {
    listenfullscreen(this.setScreen);
  },
  computed: {
    ...mapState({
      showDebug: state => state.common.showDebug,
      showTheme: state => state.common.showTheme,
      showLock: state => state.common.showLock,
      showFullScren: state => state.common.showFullScren,
      showCollapse: state => state.common.showCollapse,
      showSearch: state => state.common.showSearch,
      showMenu: state => state.common.showMenu,
      showColor: state => state.common.showColor,
      currentTenantAll: state => state.user.currentTenantAll,
    }),
    ...mapGetters([
      "userInfo",
      "isFullScren",
      "tagWel",
      "tagList",
      "isCollapse",
      "tag",
      "logsLen",
      "logsFlag"
    ])
  },
  methods: {
    handleScreen() {
      fullscreenToggel();
    },
    setCollapse() {
      this.$store.commit("SET_COLLAPSE");
    },
    setScreen() {
      this.$store.commit("SET_FULLSCREN");
    },
    switchTenant() {
      this.$refs.topTenant.show();
    },
    logout() {
      this.$confirm(this.$t("logoutTip"), this.$t("tip"), {
        confirmButtonText: this.$t("submitText"),
        cancelButtonText: this.$t("cancelText"),
        type: "warning"
      }).then(() => {
        this.$store.dispatch("LogOut").then(() => {
          resetRouter();
          this.$router.push({path: "/login"});
          window.location.reload();
        });
      });
    },
    AiCOSLicense(){
      //更新AiCOS
      this.LicenseTitle = '系统授权';
      this.lsData.handleType = 'AiCOSLicense';
      this.lsData.isApp = false;
      this.lsData.needLast = true;
      this.lsData.params = {
      }
      this.isShow = true ;
    },
    showUpdateLog(){
      this.updateLogTag = true;
    },
  }
};
</script>

<style lang="scss" scoped>
.robot-train {
  /deep/ .header-assistant-icon {
    line-height: 0;
    margin-top: 16px;

    img {
      width: 26px;
      margin: 0;
    }
    .desk-window-warnIcon {
      width: 16px;
      top: -5px;
      margin: 0;
      right: -10px;
    }

  }
}
.top-bar-userInfo {
  display: flex;
  align-items: center;
  .top-bar-userAccount {
    display: inline-block;
  }
  .top-bar-tenantName {
    display: inline-block;
    max-width: 200px;
    overflow: hidden;
    white-space:nowrap;
    text-overflow:ellipsis;
    margin: 0 8px;
  }
}
</style>
